//
//  YueyouViewController.m
//  MiaoTu
//
//  Created by dllo on 16/9/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YueyouViewController.h"
//#import "YueyouHeaderView.h"
#import "UIView+Frame.h"
#import "MyLayout.h"
#import "Masonry.h"
#import "YueyouNormalTableCell.h"
#import "YueyouRequireTableCell.h"

#define kYueyouNormalTableCell @"YueyouNormalTableCellIdentifier"
#define kYueyouRequireTableCell @"YueyouRequireTableCellIdentifier"

@interface YueyouViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UITextField *locText;
@end

@implementation YueyouViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStylePlain target:self action:@selector(nextPage)];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.dk_width, self.view.dk_height - 64) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [self createTableHeaderView];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerNib:[UINib nibWithNibName:@"YueyouNormalTableCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kYueyouNormalTableCell];
    [_tableView registerNib:[UINib nibWithNibName:@"YueyouRequireTableCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kYueyouRequireTableCell];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

- (void)createTableHeaderView {
    MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:MyLayoutViewOrientation_Vert];
    rootLayout.padding = UIEdgeInsetsMake(24, 24, 24, 24);
    rootLayout.frame = CGRectMake(0, 0, CGRectGetWidth(self.tableView.frame), 0);
    rootLayout.myLeftMargin = rootLayout.myRightMargin = 0;
    rootLayout.backgroundColor = [UIColor colorWithWhite:0.925 alpha:1.000];

    MyRelativeLayout *locView = [MyRelativeLayout new];
    locView.myLeftMargin = locView.myRightMargin = 0;
    locView.myHeight = 64;
    [rootLayout addSubview:locView];
    locView.backgroundColor = [UIColor whiteColor];
    locView.layer.cornerRadius = 4;
    locView.layer.masksToBounds = YES;
    
    UIImageView *locImage = [UIImageView new];
    locImage.image = [UIImage imageNamed:@"yueyou_loc"];
    locImage.widthDime.equalTo(@25);
    locImage.heightDime.equalTo(@25);
    locImage.centerYPos.equalTo(locView.centerYPos);
    locImage.leftPos.equalTo(locView.leftPos).offset(8);
    [locView addSubview:locImage];
    
    UITextField *locText = [UITextField new];
    locText.leftPos.equalTo(locImage.rightPos).offset(8);
    locText.rightPos.equalTo(locView.rightPos);
    locText.heightDime.equalTo(locView.heightDime);
    locText.topPos.equalTo(locView.topPos);
    [locView addSubview:locText];
    locText.text = @"大连市";
    
    MyRelativeLayout *desView = [MyRelativeLayout new];
    desView.myLeftMargin = desView.myRightMargin = 0;
    desView.myHeight = 64;
    desView.myTopMargin = 24;
    [rootLayout addSubview:desView];
    desView.backgroundColor = [UIColor whiteColor];
    desView.layer.cornerRadius = 4;
    desView.layer.masksToBounds = YES;
    
    UIImageView *desImage = [UIImageView new];
    desImage.image = [UIImage imageNamed:@"yueyou_des"];
    desImage.widthDime.equalTo(@25);
    desImage.heightDime.equalTo(@25);
    desImage.centerYPos.equalTo(desView.centerYPos);
    desImage.leftPos.equalTo(desView.leftPos).offset(8);
    [desView addSubview:desImage];
    
    UITextField *desText = [UITextField new];
    desText.leftPos.equalTo(desImage.rightPos).offset(8);
    desText.rightPos.equalTo(desView.rightPos);
    desText.heightDime.equalTo(desView.heightDime);
    desText.topPos.equalTo(desView.topPos);
    [desView addSubview:desText];
    desText.placeholder = @"可输入多个目的地以空格键分开";
    
    MyRelativeLayout *dateView = [MyRelativeLayout new];
    dateView.myLeftMargin = dateView.myRightMargin = 0;
    dateView.myHeight = 64;
    dateView.myTopMargin = 24;
    [rootLayout addSubview:dateView];
    dateView.backgroundColor = [UIColor whiteColor];
    dateView.layer.cornerRadius = 4;
    dateView.layer.masksToBounds = YES;
    
    UIImageView *dateImage = [UIImageView new];
    dateImage.image = [UIImage imageNamed:@"yueyou_date"];
    dateImage.widthDime.equalTo(@25);
    dateImage.heightDime.equalTo(@25);
    dateImage.centerYPos.equalTo(dateView.centerYPos);
    dateImage.leftPos.equalTo(dateView.leftPos).offset(8);
    [dateView addSubview:dateImage];
    
    UITextField *dateText = [UITextField new];
    dateText.leftPos.equalTo(dateImage.rightPos).offset(8);
    dateText.rightPos.equalTo(dateView.rightPos);
    dateText.heightDime.equalTo(dateView.heightDime);
    dateText.topPos.equalTo(dateView.topPos);
    [dateView addSubview:dateText];
    dateText.placeholder = @"请选择往返时间";
    
    MyRelativeLayout *liveTogetherView = [MyRelativeLayout new];
    liveTogetherView.myLeftMargin = liveTogetherView.myRightMargin = 0;
    liveTogetherView.myHeight = 64;
    liveTogetherView.myTopMargin = 24;
    [rootLayout addSubview:liveTogetherView];
    liveTogetherView.backgroundColor = [UIColor whiteColor];
    liveTogetherView.layer.cornerRadius = 4;
    liveTogetherView.layer.masksToBounds = YES;
    
    UILabel *liveTogetherLabel = [UILabel new];
    liveTogetherLabel.leftPos.equalTo(liveTogetherView.leftPos).offset(8);
    liveTogetherLabel.centerYPos.equalTo(liveTogetherView.centerYPos);
    [liveTogetherView addSubview:liveTogetherLabel];
    liveTogetherLabel.text = @"求拼房";
    [liveTogetherLabel sizeToFit];
    
    UISwitch *liveTogetherSwitch = [UISwitch new];
    liveTogetherSwitch.centerYPos.equalTo(liveTogetherLabel.centerYPos);
    liveTogetherSwitch.rightPos.equalTo(liveTogetherView.rightPos).offset(8);
    [liveTogetherView addSubview:liveTogetherSwitch];
    
    [rootLayout layoutIfNeeded];
    self.tableView.tableHeaderView = rootLayout;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0 || indexPath.row == 1) {
        YueyouNormalTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kYueyouNormalTableCell forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (indexPath.row == 0) {
            cell.titleLabel.text = @"费用说明";
            cell.wayLabel.text = @"线下AA";
        } else if (indexPath.row == 1) {
            cell.titleLabel.text = @"约伴人数";
            cell.wayLabel.text = @"1人";
        }
        return cell;
    } else if (indexPath.row == 2) {
        YueyouRequireTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kYueyouRequireTableCell forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0 || indexPath.row == 1) {
        return 50;
    } else {
        return 230;
    }
}

- (void)nextPage {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
